package com.huishu.order.fegin.fallback;

import com.huishu.commons.pojo.Result;
import com.huishu.commons.pojo.dto.DeductionStockDTO;
import com.huishu.commons.pojo.vo.CartItemGoodsVO;
import com.huishu.commons.pojo.vo.FullReductionVO;
import com.huishu.order.fegin.GoodsFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName：GoodsFeignClientFallBack
 * @Author: ljj
 * @Date: 2023/4/11 9:31
 */
@Slf4j
@Component
public class GoodsFeignClientFallBack implements FallbackFactory<GoodsFeignClient> {

    @Override
    public GoodsFeignClient create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();
        if (!StringUtils.isEmpty(msg)) {
            log.error(msg);
        }
        return new GoodsFeignClient() {

            @Override
            public Result<List<FullReductionVO>> find(List<Long> ids) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CartItemGoodsVO>> findCartItemGoods(List<Long> ids) {
                return Result.fail(msg);
            }

            @Override
            public Result deductionStock(List<DeductionStockDTO> deductionStocks) {
                return Result.fail(msg);
            }

            @Override
            public Result findGoodsById(Long productId) {
                return Result.fail(msg);
            }
        };
    }
}
